﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sorting
{
    class Person : IComparable
    {
        #region Constructors

        /// <summary>
        /// Create new object of Person class
        /// </summary>
        public Person() { }

        /// <summary>
        /// Create new object of Person class with params
        /// </summary>
        /// <param name="age"></param>
        /// <param name="fName"></param>
        /// <param name="lName"></param>
        public Person(int age, string fName, string lName)
        {
            this.Age = age;
            this.FirstName = fName;
            this.LastName = lName; 
        }

        #endregion

        #region Properties

        public string LastName
        {
            get { return mLastName; }
            set { mLastName = value; }
        }

        public string FirstName
        {
            get { return mFirstName; }
            set { mFirstName = value; }
        }       

        public int Age
        {
            get { return mAge; }
            set { mAge = value; }
        }        

        #endregion

        #region IComparable implementation

        public int CompareTo(object objA)
        {
            int result;
            Person itemA = objA as Person;

            if (itemA.mAge > this.mAge)
            {
                result = 1;
            }
            else if (itemA.mAge < this.mAge)
            {
                result = -1;
            }
            else
            {
                result = 0;
            }

            return result;
        }

        #endregion

        #region Get the list of persons

        /// <summary>
        ///  Get the list of persons
        /// </summary>
        /// <returns>Mass of persons</returns>
        public static Person[] GetMassPersons()
        {
            return new Person[]
            {
                new Person(15, "Angel_15", "Jons_15"),
                new Person(45, "Angel_45", "Jons_45"),
                new Person(67, "Angel_67_1", "Jons_67_1"),
                new Person(67, "Angel_67", "Jons_67"),
                new Person(25, "Angel_25", "Jons_25"),
                new Person(75, "Angel_75", "Jons_75")
            };
        }

        #endregion

        #region Override ToString method

        /// <summary>
        /// Override ToString method
        /// </summary>
        /// <returns>String</returns>
        public override string ToString()
        {
            return string.Format("{0, 10} {1, 10} {2, 10}", 
                this.FirstName, this.LastName, this.Age);
        }

        #endregion

        #region Fields

        private int mAge;
        private string mFirstName;
        private string mLastName;

        #endregion
    }
}
